package com.vegetable.modules.entity.inbound;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.vegetable.common.base.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 加工打包完工成品
 * </p>
 *
 * @author wangruijie
 * @since 2024-03-21
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="PackDeliveryDetail对象", description="加工打包完工成品")
public class PackDeliveryDetail extends BaseEntity {

    @ApiModelProperty(value = "0生产领料耗用；1生产完工产品；")
    private Integer detailType;

    @ApiModelProperty(value = "主表id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long deliveryId;

    @ApiModelProperty(value = "库存的id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long stockId;

    @ApiModelProperty(value = "订单时间（批次）")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private Date orderTime;

    @ApiModelProperty(value = "商品ID")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long commodityId;

    @ApiModelProperty(value = "商品编码")
    private String commodityCode;

    @ApiModelProperty(value = "商品名称")
    private String commodityName;

    @ApiModelProperty(value = "规格ID")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long specsId;

    @ApiModelProperty(value = "标准")
    private BigDecimal standard;

    @ApiModelProperty(value = "单价")
    private BigDecimal unitPrice;

    @ApiModelProperty(value = "数量")
    private Integer number = 0;

    @ApiModelProperty(value = "重量")
    private BigDecimal weight = BigDecimal.ZERO;

    @ApiModelProperty(value = "商品金额")
    private BigDecimal goodsMoney;

    @ApiModelProperty(value = "包装金额")
    private BigDecimal packageMoney;

    @ApiModelProperty(value = "金额")
    private BigDecimal money;

    @ApiModelProperty(value = "成本")
    private BigDecimal cost;

    @ApiModelProperty(value = "成本单价（按重量算）")
    @TableField(exist = false)
    private BigDecimal costWeight;

    @ApiModelProperty(value = "包装成本")
    @TableField(exist = false)
    private String packageCost;

    @ApiModelProperty(value = "初始重量")
    @TableField(exist = false)
    private BigDecimal initWeight;

    @ApiModelProperty(value = "商品其他费用")
    @TableField(exist = false)
    private List<OrderCost> costs;

//    @ApiModelProperty(value = "商品材料")
//    @TableField(exist = false)
//    private List<PackDeliveryDetailMaterial> materials;

    @ApiModelProperty(value = "损耗比")
    private BigDecimal lossRate;

    public Integer getNumber(){
        return ObjectUtil.isNotNull(number) ? number : 0;
    }

    @ApiModelProperty(value = "商品包装费用")
    @TableField(exist = false)
    private List<AgentDeliveryDetailPack> materials;

    @ApiModelProperty(value = "包装成本-销售显示")
    @TableField(exist = false)
    private BigDecimal packageCostForSales = BigDecimal.ZERO;

    public List<AgentDeliveryDetailPack> getMaterials(){
        return CollectionUtil.isEmpty(materials) ? new ArrayList<>() : materials;
    }
}
